$(document).on('ajaxBeforeSend', function(e, xhr, options){
  // This gets fired for every Ajax request performed on the page.
  // The xhr object and $.ajax() options are available for editing.
  // Return false to cancel this request.

})


$.ajaxSettings = $.extend($.ajaxSettings, {
	beforeSend: function (XMLHttpRequest) {  
　　　　XMLHttpRequest.setRequestHeader('accesstoken', localStorage.getItem('token'));
	},
	error: function( responseXHR ){
		//code是不是json，是不是过期了
		//如果过期了，清空token localStorage，重定向到login
		//如果404、php内部错误，console出错信息 
		var responseValue = responseXHR.responseText;
		
		if(responseXHR.status==500 && isJSON_test(responseValue)){ 
			var responseJSON = JSON.parse(responseValue);
			if(responseJSON.code == 10001){ 
				console.log('token expired');
				window.location.href = '/Mobile/Show/action?page=login' 
			}else if(responseJSON.code == 10004){
				//弹窗提示，系统异常
				alert('系统异常');
				window.location.href = '/Mobile/Show/action?page=login' 
			}
		}
	}
});

function isJSON_test(str) {
    if (typeof str == 'string') {
        try {
            var obj=JSON.parse(str);
            return true;
        } catch(e) {
            return false;
        }
    }
 }　